home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
nasm20
/
nasm20s.zoo
/
asm65.y
< prev
next >
Wrap
Text File
|
1993-01-22
|
12KB
|
323 lines
%{
/* ---------------------------------------------------------------------- */
/* Copyright (C) 1992 by Natürlich! */
/* This file is copyrighted! */
/* Refer to the documentation for details. */
/* ---------------------------------------------------------------------- */
/*#define YYDEBUG*/
#include <stdio.h>
#include "defines.h"
#undef DEBUG
#include "structs.h"
#include "nasm.h"
#include "labels.h"
#include "code.h"
#include "buffer.h"
#include "exprfast.h"
#include "op.h"
#if DEBUG
#define bputchar( c) putchar( c)
#define dbprintf( s) puts( s)
#else
#define dbputchar( c)
#define dbprintf( s)
#endif
#ifdef NIL
#undef NIL
#endif
#define NIL ((char *) 0)
#define ENIL ((expr *) 0)
extern int _in_instr,
_in_doteq,
_call_macro,
wasstrlen,
state,
fully_mac65;
extern buffer huge *bp;
extern word __pc;
static char undefined[] = { 9, 0, 'u','n','d','e','f','i','n','e','d' },
*lastident;
static int footok;
static lword fooval;
#define adrmod footok /* screws the debugger of course (har har) */
typedef union
{
lword u;
byte *b;
char *c;
expr *e;
lexpr *l;
} YYSTYPE;
#define _ul lword
%}
%start file
/* ---------------------------------------------------------- */
/* The order of these tokens MIGHT be VERY IMPORTANT */
/* ---------------------------------------------------------- */
%token <u> T_DOTEQ T_IF T_ELSE T_LOCAL T_EOL T_NUMBER T_ZEXT
%token <u> T_ENDIF T_ORG T_DS T_WORD T_BYTE T_SBYTE T_OPT
%token <u> T_MACRO T_ENDM T_END T_NUM T_OBJ T_MLIST T_INCLUDE
%token <u> T_ERROR T_TITLE T_DBYTE T_TAB T_FLOAT T_CBYTE T_XREF
%token <u> T_SET T_LIST T_ERR T_ACCU T_CHAR T_NOT T_DEF
%token <u> T_REF T_CLIST T_EJECT T_PAGE T_XFLOAT T_UNDEF T_WARN
%token <u> T_REPT T_CALL
%token <c> T_IDENT T_STRING T_LABEL T_FILE
%token <e> T_EXPR
%token <b> T_INSTR
%type <e> irest s_expr a_expr modif __expr
%type <l> t_expr u_expr si_expr mi_expr i_expr fubar ei_expr
%left <e> ',' T_NO /* not really... */
%left <e> T_OR
%left <e> T_AND
%nonassoc <e> T_LEQ T_GEQ '=' T_NEQ '>' '<'
%left MIDDLE
%left <e> '!' '^' '&'
%left <e> '+' '-'
%left <e> '*' '/' '\\'
%left HIGHEST
/* next five tokens are actually not used by YACC, but elsewhere */
%token <u> T_MPARA
%token <c> T_MSPARA
%token <u> T_MLPARA
%token <c> T_MLSPARA
%token <l> T_PARA
%token REALHIGH
%%
file : source line
| source
;
source: source sline
{
inc_line();
_in_instr = 0;
dbputchar( '\n');
}
|
| error
{
nterror("unwanted token appeared", yychar);
while( (yychar = yylex()) && yychar != T_EOL);
inc_line();
if( ! yychar)
return;
yyerrok;
yyclearin;
}
;
sline : line T_EOL
| T_EOL
;
line : T_LABEL
{
enter_pclabel( $1);
}
nline
{
dbprintf("T_LABEL nline [done with line]\n\n");
}
| T_LABEL '=' '=' __expr
{
enter_elabel( $1, $4, L_ZERO | L_LINKZERO);
dbprintf("T_LABEL == s_expr [done with line]\n\n");
}
| T_LABEL '=' __expr
{
enter_elabel( $1, $3, L_NORMAL);
dbprintf("T_LABEL = s_expr [done with line]\n\n");
}
| T_LABEL T_DOTEQ { _in_doteq = 1; }
__expr
{
_in_doteq = 0;
enter_elabel( $1, $4, L_EQU);
dbprintf("T_LABEL .= s_expr [done with line]\n\n");
}
| T_LABEL {
enter_pclabel( $1);
dbprintf("T_LABEL [done with line]\n\n");
}
| nline {
dbprintf("regular line [done]\n\n");
}
;
nline : T_INSTR { _in_instr = 1; } irest
{ generate( $1,adrmod,$3);}
| T_IF __expr { if_treat( $2); }
| T_ELSE { else_treat(); }
| T_ENDIF { endif_treat(); }
| T_ORG __expr { setorg( $2, 0); }
| T_DS __expr { reserve( $2); }
| T_WORD i_expr { dropwords( $2); }
| T_DBYTE i_expr { dropdbytes( $2); }
| T_BYTE modif si_expr { dropbytes( $2, $3, 0); }
| T_CBYTE modif si_expr { dropbytes( $2, $3, 1); }
| T_SBYTE modif si_expr { dropsbytes( $2, $3); }
| T_ZEXT T_IDENT { page0decl( $2); }
| T_FLOAT f_expr
| T_CALL T_IDENT { call_macro( $2); }
| T_IDENT { lastident = NIL;
_call_macro = 1; }
ei_expr { _call_macro = 0;
do_macro( $1, $3); }
| T_REPT __expr T_IDENT { lastident = NIL;
_call_macro = 1; }
ei_expr { _call_macro = 0;
rept_macro( $2, $3, $5);}
| T_TAB i_expr { dbprintf("T_TAB"); }
| T_OPT o_expr { dbprintf("T_OPT"); }
| T_SET __expr ',' __expr { dbprintf("T_SET"); }
| T_UNDEF T_IDENT { undefine( $2); }
| T_MACRO T_IDENT {
load_macro( $2);
dbprintf("*** DONE WITH .MACRO ***");
}
| T_INCLUDE '#' T_FILE {
footok = yylex();
fooval = yylval.u;
include( $3, ".h65");
fix_include( footok, fooval);
}
| T_END { return( 0); }
| T_LOCAL { do_local(); }
| T_TITLE T_STRING { dbprintf("TITLE\n"); }
| T_PAGE T_STRING { dbprintf("PAGE\n"); }
| T_ERROR T_STRING { nerror( $2 + 2); }
| T_WARN T_STRING { nwarning( $2 + 2); }
;
irest : __expr ',' 'X' { adrmod = C_RELX; }
| __expr ',' 'Y' { adrmod = C_RELY; }
| '(' __expr ',' 'X' ')' { adrmod = C_INDX; $$ = $2; }
| '(' __expr ')' ',' 'Y' { adrmod = C_INDY; $$ = $2; }
| '#' __expr { adrmod = C_IMM; $$ = $2; }
| '(' __expr ')' { adrmod = C_IND; $$ = $2; }
| __expr { adrmod = C_ABS; }
| T_ACCU { adrmod = C_ACCU; $$ = ENIL; }
| { adrmod = C_IMPL; $$ = ENIL; }
;
a_expr: T_NUMBER { $$ = ival_pl( (word) $1); }
| T_IDENT { $$ = lval_pl( l